//
//  LoginView.m
//  LClass
//
//  Created by 严军 on 16/5/29.
//  Copyright © 2016年 YanJun. All rights reserved.
//

#import "LoginView.h"

@implementation LoginView
{
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        [self initLayout];
    }
    return self;
}


-(void)initLayout{

    self.backgroundColor=ThemeBackgroundColor;
    
    //添加logo
    UIImageView* logoimg=[[UIImageView alloc]init];
    [self addSubview:logoimg];
    _logoview=logoimg;
    logoimg.image=[UIImage imageNamed:@"ke"];
    [logoimg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.mas_width).multipliedBy(0.25);
        make.height.equalTo(self.mas_width).multipliedBy(0.25);
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).multipliedBy(0.5);
    }];
    
    //添加登录用户名输入框
    UIView* loginview=[[UIView alloc]init];
    [self addSubview:loginview];
    [[Utility sharedInstance] setLayerView:loginview borderW:1 borderColor:[UIColor grayColor] radius:3.0];
    [loginview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_logoview.mas_bottom).offset(30);
        make.width.equalTo(self).multipliedBy(0.75);
        make.height.equalTo(self).multipliedBy(0.16);
        make.centerX.equalTo(self);
    }];
    
    //中间线
    UIView* line=[[UIView alloc]init];
    [loginview addSubview:line];
    line.backgroundColor=[UIColor grayColor];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(1);
        make.width.equalTo(loginview);
        make.center.equalTo(loginview);
    }];
    
    //用户名
    UILabel*labName=[[UILabel alloc]init];
    labName.text=@"用户名";
    labName.textColor=[UIColor darkGrayColor];
    labName.font=[UIFont systemFontOfSize:17];
    [loginview addSubview:labName];
    [labName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(loginview).offset(10);
        make.width.mas_equalTo(60);
        make.centerY.equalTo(loginview).multipliedBy(0.5);
    }];
    
    //用户名输入框
    UITextField* tfusername=[UITextField new];
    tfusername.placeholder=@"请输入用户名";
    [loginview addSubview:tfusername];
    _TF_Username=tfusername;
    [tfusername mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(labName.mas_right).offset(10);
        make.top.equalTo(loginview).offset(5);
        make.bottom.equalTo(line).offset(5);
        make.right.equalTo(loginview.mas_right).offset(-5);
    }];
    
    //密码输入框
    UITextField* tfpassword=[UITextField new];
    tfpassword.placeholder=@"请输入密码";
    tfpassword.secureTextEntry=YES;
    [loginview addSubview:tfpassword];
    _TF_Password=tfpassword;
    [tfpassword mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_TF_Username);
        make.top.equalTo(line).offset(5);
        make.bottom.equalTo(loginview).offset(5);
        make.right.equalTo(loginview.mas_right).offset(-5);
    }];
    
    
    //密码
    UILabel*labPassword=[[UILabel alloc]init];
    labPassword.text=@"密码";
    labPassword.textColor=[UIColor darkGrayColor];
    labPassword.font=[UIFont systemFontOfSize:17];
    [loginview addSubview:labPassword];
    [labPassword mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(loginview).offset(10);
        make.centerY.equalTo(loginview).multipliedBy(1.5);
    }];
    
    //登录按钮
    UIButton* btnlogin=[[UIButton alloc]init];
    [self addSubview:btnlogin];
    _Btn_Login=btnlogin;
    btnlogin.backgroundColor=[UIColor redColor];
    [btnlogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnlogin setTitle:@"登录" forState:UIControlStateNormal];
    [btnlogin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(loginview.mas_bottom).offset(30);
        make.width.equalTo(loginview);
        make.height.equalTo(loginview).multipliedBy(0.5);
        make.centerX.equalTo(self);
    }];
    [btnlogin addTarget:self action:@selector(clickLogin:) forControlEvents:UIControlEventTouchUpInside];
    //注册按钮
    UIButton* btnregister=[[UIButton alloc]init];
    [self addSubview:btnregister];
    _Btn_Register=btnregister;
    [btnregister setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btnregister setTitle:@"注册" forState:UIControlStateNormal];
    btnregister.titleLabel.font=[UIFont systemFontOfSize:17];
    [btnregister mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(btnlogin.mas_bottom).offset(30);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(20);
        make.left.equalTo(btnlogin);
    }];
    [btnregister addTarget:self action:@selector(clickRegist:) forControlEvents:UIControlEventTouchUpInside];
    
    //忘记密码？
    UIButton* btnforget=[[UIButton alloc]init];
    [self addSubview:btnforget];
    _Btn_ForgetPassword=btnforget;
    [btnforget setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btnforget setTitle:@"忘记密码？" forState:UIControlStateNormal];
    btnforget.titleLabel.font=[UIFont systemFontOfSize:17];
    [btnforget mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(btnlogin.mas_bottom).offset(30);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(20);
        make.right.equalTo(btnlogin);
    }];
    [btnforget addTarget:self action:@selector(skipalert:) forControlEvents:UIControlEventTouchUpInside];
  
    
}

-(void)clickLogin:(id)sender
{
    NSDictionary* dic=@{@"userName":_TF_Username.text,@"passWord":_TF_Password.text};
    _loginblock(dic);
}

-(void)clickRegist:(id)sender
{
    _registeblock();
}
-(void)skipalert:(id)sender
{
    
}
@end
